package com.hmall.search.web;

import com.hmall.feign.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     *  自动补全搜索
     * @param key 用户输入的内容
     * @return 搜索到的内容
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String key){
        return  searchService.getSuggestion(key);
    }

    /**
     *  基本搜索功能
     * @param params 请求的参数
     * @return 结果
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params) {
        return searchService.search(params);
    }

    /**
     * 聚合
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }
}
